<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="-">
                <el-breadcrumb-item replace>客服管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :inline="true" :model="form">
                    <el-form-item label="操作人">
                        <el-input
                            placeholder="请输入账户名"
                            clearable
                            @keyup.native.enter="handleSearch"
                            v-model="query.name1"
                            class="handle-input mr10"
                        ></el-input>
                    </el-form-item>

                    <el-form-item label="工单类型">
                        <el-select v-model="query.name" placeholder="" clearable class="handle-select mr10">
                            <el-option key="1" label="全部" value="全部"></el-option>
                            <el-option key="2" label="用户投诉" value="用户投诉"></el-option>
                            <el-option key="3" label="用户退款" value="用户退款"></el-option>
                            <el-option key="4" label="账号注销" value="账号注销"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="状态">
                        <el-select v-model="query.name" placeholder="" clearable class="handle-select mr10">
                            <el-option key="1" label="全部" value="全部"></el-option>
                            <el-option key="2" label="处理中" value="处理中"></el-option>
                            <el-option key="3" label="待处理" value="待处理"></el-option>
                            <el-option key="4" label="已完结" value="已完结"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="优先级">
                        <el-select v-model="query.name" placeholder="" clearable class="handle-select mr10">
                            <el-option key="1" label="全部" value="全部"></el-option>
                            <el-option key="2" label="紧急" value="紧急"></el-option>
                            <el-option key="3" label="一般" value="一般"></el-option>
                            <el-option key="4" label="低" value="低"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="时间范围">
                        <div class="block">
                            <el-date-picker
                                v-model="query.name"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                            >
                            </el-date-picker>
                        </div>
                    </el-form-item>

                    <el-form-item label="">
                        <el-button type="primary" @click="handleSearch">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>

            <div class="handle-box_">
                <!-- <span class="title">操作日志列表</span> -->
                <el-button type="primary" @click="handleNewWorkOrder">新建工单</el-button>
            </div>

            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column label="工单号" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="工单类型" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="内容" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="状态" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="优先级" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="操作人" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="操作时间" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" @click="handleEdit(scope.$index, scope.row)">重开</el-button>
                        <el-button type="text" @click="handleWorkOrderDetail(scope.$index, scope.row)">处理</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total,sizes, prev, pager, next, jumper"
                    :page-sizes="[5, 10, 20, 30]"
                    @size-change="handleSizeChange"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 创建账户 -->
        <el-dialog title="" :visible.sync="createVisible" width="50%">
            <el-form ref="form" :model="form" label-width="auto">
                <el-form-item label="用户名">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>

                <el-form-item label="密码">
                    <el-input v-model="form.name" type="password"></el-input>
                </el-form-item>

                <el-form-item label="角色">
                    <!-- <el-input v-model="form.name"></el-input> -->
                    <el-checkbox-group v-model="checkList">
                        <el-checkbox label="管理员"></el-checkbox>
                        <el-checkbox label="超级管理员"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item>

                <el-form-item label="管理员名称">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <!-- <el-form-item label="地址">
                    <el-input v-model="form.address"></el-input>
                </el-form-item> -->
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="saveCreate">创建</el-button>
                <el-button @click="createVisible = false">取消</el-button>
            </span>
        </el-dialog>

        <!-- 编辑 -->
        <el-dialog title="" :visible.sync="editVisible" width="50%">
            <el-form ref="form" :model="form" label-width="auto">
                <el-form-item label="用户名">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>

                <el-form-item label="密码">
                    <el-input v-model="form.name" type="password"></el-input>
                </el-form-item>

                <el-form-item label="角色">
                    <!-- <el-input v-model="form.name"></el-input> -->
                    <el-checkbox-group v-model="checkList">
                        <el-checkbox label="管理员"></el-checkbox>
                        <!-- <el-checkbox label="超级管理员"></el-checkbox> -->
                    </el-checkbox-group>
                </el-form-item>

                <el-form-item label="管理员名称">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <!-- <el-form-item label="地址">
                    <el-input v-model="form.address"></el-input>
                </el-form-item> -->
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="handleConfirmEdit">确认修改</el-button>
                <el-button @click="editVisible = false">取消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
// import { fetchData } from '@/api/index';
export default {
    name: 'AccountManage',
    data() {
        return {
            checkList: [],
            query: {
                address: '',
                name: '',
                pageIndex: 0,
                pageSize: 10
            },
            tableData: [
                {
                    name: '11'
                }
            ],
            multipleSelection: [],
            delList: [],
            createVisible: false,
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    activated() {
        // this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            // fetchData(this.query).then(res => {
            //     console.log(res);
            //     this.tableData = res.list;
            //     this.pageTotal = res.pageTotal || 50;
            // });
        },
        handleConfirmEdit() {
            this.editVisible = false;
        },
        // 创建账户
        handleCreateAccount() {
            this.createVisible = true;
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 0);
            this.getData();
        },
        // 新建工单
        handleNewWorkOrder() {},
        // 工单详情
        handleWorkOrderDetail(index, row) {
            // 二次确认删除
            // this.$confirm('确定要删除吗？', '提示', {
            //     type: 'warning'
            // })
            //     .then(() => {
            //         this.$message.success('删除成功');
            //         this.tableData.splice(index, 1);
            //     })
            //     .catch(() => {});

            this.$router.replace({
                path: '/customer/work/order/detail'
            });
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
            }
            this.$message.error(`删除了${str}`);
            this.multipleSelection = [];
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveCreate() {
            this.createVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        },
        handleSizeChange(val) {
            this.$set(this.query, 'pageSize', val);
            this.getData();
        }
    }
};
</script>

<style scoped lang="scss">
.handle-box {
    margin-bottom: 20px;
    // .el-form {
    //     display: grid;
    //     grid-auto-flow: column;
    //     justify-content: flex-start;
    //     .el-form-item {
    //         width: 100%;
    //         .el-form-item__content {
    //             .el-select,
    //             .handle-input {
    //                 width: 100%;
    //             }
    //         }
    //     }
    // }
}
.handle-box_ {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 9px;
    padding-bottom: 9px;
    border-bottom: 1px solid #dcdfe6;
}
.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
